package com.example.testdao;

import java.util.List;


import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

import com.stein.app.DataBaseContext;
import com.stein.app.TApplication;
import com.stein.app.TConstant;
import com.stein.db.util.DaoUtils;
import com.stein.entity.Score;
import com.stein.entity.ScoreDao;
import com.stein.entity.Student;
import com.stein.entity.StudentDao;
import com.stein.entity.Subject;
import com.stein.entity.SubjectDao;

//KEEP FIELDS - put your custom fields here

//KEEP FIELDS END

//KEEP METHODS - put your custom methods here

//KEEP METHODS END

public class MainActivity extends Activity {
	private StudentDao studentDao;
	private ScoreDao scoreDao;
	private SubjectDao subjectDao;
	private Cursor cursor;
	static {
		TConstant.DATABASE_NAME = "sudents-db";
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		DataBaseContext dataBaseContext =  new DataBaseContext(this);
		studentDao = TApplication.getDaoSession(dataBaseContext).getStudentDao();
		scoreDao = TApplication.getDaoSession(dataBaseContext).getScoreDao();
		subjectDao = TApplication.getDaoSession(dataBaseContext).getSubjectDao();
		DaoUtils.clear(studentDao);
		DaoUtils.clear(scoreDao);
		DaoUtils.clear(subjectDao);
		List<Student> students = DaoUtils.queryAllData(studentDao);
		Log.d("", "数据库测试------查询所有--"+students.isEmpty());
		if(students.isEmpty()){
			studentDao.insert(new Student(null, "张三", true, 12));
			studentDao.insert(new Student(null, "张三1", true, 12));
		}
		students = DaoUtils.queryAllData(studentDao);
		Log.d("", "数据库测试------查询所有--"+students);
		List<Score>scores = DaoUtils.queryAllData(scoreDao);
		if(scores.isEmpty()){
			DaoUtils.insert(scoreDao, new Score(null,1L));
			DaoUtils.insert(scoreDao, new Score(null,1L));
			DaoUtils.insert(scoreDao, new Score(null,2L));
		}
		scores = DaoUtils.queryAllData(scoreDao);
		Log.d("", "数据库测试------查询所有--"+scores);
		List<Subject> subjects = DaoUtils.queryAllData(subjectDao);
		if(subjects.isEmpty()){
			DaoUtils.insert(subjectDao, new Subject(null, 122F, "英文", 1L));
			DaoUtils.insert(subjectDao, new Subject(null, 122F, "中文", 1L));
			DaoUtils.insert(subjectDao, new Subject(null, 1.2F, "数学", 2L));
			DaoUtils.insert(subjectDao, new Subject(null, 122F, "英文", 3L));
		}
		subjects = DaoUtils.queryAllData(subjectDao);
		Log.d("", "数据库测试------查询所有--"+subjects);
		
		
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
